package iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.serviceConnection;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;

import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.IProductService;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.serviceImpl.ProductService;

public class ProductServiceConnection implements ServiceConnection {
    private IProductService productService;
    private boolean mIsBound = false;

    public interface OnServiceConnectedCallback {
        void onServiceConnected(IProductService service);
    }
    private final OnServiceConnectedCallback callback;



    public ProductServiceConnection(OnServiceConnectedCallback callback) {
        this.callback = callback;
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        ProductService.LocalBinder binder = (ProductService.LocalBinder) service;
        productService = binder.getService();
        mIsBound = true;

        if (callback != null) {
            callback.onServiceConnected(productService);
        }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mIsBound = false;
    }

    public IProductService getService() {
        return productService;
    }

    public boolean isBound() {
        return mIsBound;
    }
}